package com.itheimaoa.service.customer.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.QueryResult;
import com.itheimaoa.domain.customer.Customer;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.customer.ICustomerService;

@Service("customerService")
@Transactional
public class CustomerServiceImpl extends CommonServiceImpl<Customer> implements ICustomerService {
	@Override
	public void saveEntity(Customer t) {
		t.setId(UUID.randomUUID().toString());
		super.saveEntity(t);
	}

	@Override
	public void deleteEntity(Serializable id) {
		super.deleteEntity(id);
	}

	@Override
	public void updateEntity(Customer t) {
		super.updateEntity(t);
	}

	@Override
	public Customer findEntity(Serializable id) {
		return super.findEntity(id);
	}

	@Override
	public Collection<Customer> getEntitys() {
		return super.getEntitys();
	}

	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	@Override
	public QueryResult<Customer> getQueryResult(Integer firstResult, Integer maxResult, String strWhere, Object[] params, LinkedHashMap<String, String> orderby) {
		return super.getQueryResult(firstResult, maxResult, strWhere, params, orderby);
	}

	@Override
	public Customer checkLogin(String name, String cellphone) {
		String jpql="from Customer o where o.name = ? and o.cellphone = ?";
		List<Customer> customers =this.hibernateTemplate.find(jpql,new Object[]{name,cellphone});
		if(customers!=null && customers.size()>0)
			return customers.get(0);
		return null;
	}

}